package com.imooc.spark

import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.SparkSession


/**
  * Created by zghgchao 2017/12/22 15:29
  * SparkSession的使用
  */
object SparkSessionApp {
  def main(args: Array[String]): Unit = {
    SetLogger
    if (args.length != 1) {
      println("Usage:Path must Input!")
      System.exit(0)
    }
    var path = args(0)

    val spark = SparkSession.builder()
      .master("local[2]")
      .appName("SparkSessionApp").getOrCreate()

    //    spark.read.format("json").load()
    val people = spark.read.json(path)
    people.printSchema()
    people.show()

    spark.stop()
  }

  def SetLogger() = {
    Logger.getLogger("org").setLevel(Level.OFF)
    Logger.getLogger("com").setLevel(Level.OFF)
    System.setProperty("spark.ui.showConsoleProgress", "false")
    Logger.getRootLogger().setLevel(Level.OFF);
  }
}
